

import java.util.Arrays;
import java.util.Scanner;

public class s0127 {
    public static void main1(String[] args) {    //数组用于保存数据
         int [] array={1,2,3};
         a(array);

    }
    public static void a(int[] n){
        n[0]=100;
        System.out.println(n[0]);
    }
    public static int [] fib(int n){   //获取斐波那契数例的前n项和
        if(n<=0){
            return null;
        }
        int [] array=new int[n];
        array[0]=array[1]=1;
        for (int i=2;i<n;i++){
            array[i]=array[i-1]+array[i-2];
        }
        return array;
    }

    public static void main2(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int  n= scanner.nextInt();
        int [] array=fib(n);
        for (int i=0;i<array.length;i++){
            System.out.println(array[i]);
        }
    }


    public static void main3(String[] args) {   // 数组转字符串，便于以后打印数组
        int[] array = {1, 2, 3};
        String newarray = Arrays.toString(array);
        System.out.println(newarray);
    }

    public static void main4(String[] args) {//修改
        int  [] array={1,2,3,4,5,6};
        int[] newArray=array;
        newArray[2]=50;
        System.out.println(Arrays.toString(array));

    }

    public static void main5(String[] args) {    //拷贝数组
        int  [] array={1,2,3,4,5,6};
        int[]newArray=Arrays.copyOf(array,array.length);
        newArray[0]=50;
        System.out.println("newArray"+Arrays.toString(newArray));
        System.out.println("array"+Arrays.toString(array));
    }

    public static void main6(String[] args) {
        int  [] array={1,2,3,4,5,6};
        System.out.println(average(array));
    }
    private static double average(int[] array) {//求数组的内数据的平均数
        int sum = 0;
        for(int x : array){
            sum += x;
        }
        return (double)sum/(double)array.length;
    }

    public static void main7(String[] args) {
        int  [] array={1,2,3,4,5,6};
        System.out.println(b(array, 4));
    }
    public static int find(int[] arr,int data){//查找数组指定元素的位置
        for (int i=0;i<arr.length;i++){
            if(arr[i]==data){
                return i;
            }
        }
        return 0;
    }

    public static int b(int[] arr, int data) {//二分查找
        int left = 0;
        int right = arr.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if (data < mid) {
                right = mid - 1;
            } else if (mid < data) {
                left = mid - 1;
            } else {
                return mid;
            }
        }
        return 0;
    }

    public static void main(String[] args) {//使用Java内置的算法进行排序
        int[] array={5,9,41,52,62,81};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main9(String[] args) {
        int[] array={1,2,3,4,5,6};
        fan(array);
        System.out.println(Arrays.toString(array));
    }
    public static void fan(int[]arr){//数组逆序
        int left=0;
        int right =arr.length-1;
        while (left<right){
            int m=arr[left];
            arr[left]=arr[right];
            arr[right]=m;

            left++;
            right--;
        }
    }
}


